﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using FlyHorse.LIMS.WinApp.Utils;
using FlyHorse.LIMS.Model;
using System.Deployment.Application;
using DevExpress.XtraEditors;



namespace FlyHorse.LIMS.WinApp
{
    public partial class Form1 : RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
            InitSkinGallery();
            schedulerControl.Start = System.DateTime.Now;
        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            //...?
            // 取得版本号
            //ApplicationDeployment appd = ApplicationDeployment.CurrentDeployment;
            //this.barStaticItem_version.Caption = appd.CurrentVersion.ToString();

            // // 不走loginFOrm时候用这两句
            //FlyHorse.LIMS.Model.LoginUser ueser = new BLL.LoginUserBll().LoadEntities(m => m.LoginUserID == "1").First();
            //LoginUserUtil.LoginUser = ueser;

            string a = LoginUserUtil.LoginUser.EmpName;
            siInfo.Caption = LoginUserUtil.LoginUser.EmpName;

            //检查权限
            LoginUser loginUser = LoginUserUtil.LoginUser;
            List<Resource> resourceList = loginUser.Role.Resources.Where(m => m.IsLeftItem == true).ToList();

            for (int i = 0; i < this.navBarControl.Items.Count; i++)
            {
                DevExpress.XtraNavBar.NavBarItem currItem = navBarControl.Items[i];
                foreach (var resource in resourceList)
                {
                    if (resource.ControlName == currItem.Name)
                    {
                        currItem.Enabled = true;
                    }
                }
            }

            splashScreenManager1.CloseWaitForm();
        }


        private void CustomerManage_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.CustomerForms.CustomerMainForm customerMainForm = new BaseManageForms.CustomerForms.CustomerMainForm();
            customerMainForm.Show();
        }

        private void GoodsManage_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.GoodsForms.GoodsMainForm goodsMainForm = new BaseManageForms.GoodsForms.GoodsMainForm();
            goodsMainForm.Show();
        }

        private void TestItemManage_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.TestItemForms.TestItemMainForm testItemMainForm = new BaseManageForms.TestItemForms.TestItemMainForm();
            testItemMainForm.Show();
        }

        private void StandardSelfManage_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.StandardSelfForms.StandardSelfMainForm standardSelfMainForm = new BaseManageForms.StandardSelfForms.StandardSelfMainForm();
            standardSelfMainForm.Show();
        }

        private void StandardCustomerManage_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.StandardCustomerFroms.StandardCustomerMainForm standardCustomerMainForm = new BaseManageForms.StandardCustomerFroms.StandardCustomerMainForm();
            standardCustomerMainForm.Show();
        }

        private void navBarItem_RawReport_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.DataManageForms.ReportRawForms.ReportRawMainForm reportRawMainForm = CreateForm.CreateReportRawMainForm();
            reportRawMainForm.Show();


        }
        private void navBarItem_semiReport_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.DataManageForms.ReportSemiForms.ReportSemiMainForm reportSemiMainForm = CreateForm.CreateReportSemiMainForm();
            reportSemiMainForm.Show();
        }


        private void navBarItem_mixReport_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.DataManageForms.ReportMixForms.ReportMixMainForm ReportMixMainForm = new DataManageForms.ReportMixForms.ReportMixMainForm();
            ReportMixMainForm.Show();
        }

        private void navBarItem_productReport_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.DataManageForms.ReportProductForms.ReportProductMainForm ReportProductMainForm = CreateForm.CreateReportProductMainForm();
            ReportProductMainForm.Show();
        }

        private void StandardSemiManage_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.StandardSemiForms.StandardSemiMainForm form = new BaseManageForms.StandardSemiForms.StandardSemiMainForm();
            form.Show();
        }


        private void navBarItem_curve_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.DataAnalyzeFroms.CurveForms.CurveForm form = new DataAnalyzeFroms.CurveForms.CurveForm();
            form.Show();
        }

        private void nav_InitialItemSet_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.SystemManageForms.InitialTestItemForms.SetTestItemMainForm frm = CreateForm.CreateFromSetTestItemMainForm();
            frm.Show();

            //FlyHorse.LIMS.WinApp.SystemManageForms.InitialTestItemForms.SetTestItemMainForm form = new SystemManageForms.InitialTestItemForms.SetTestItemMainForm();
            //form.Show();
        }

        private void nav_StandardSemi_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.StandardSemiForms.StandardSemiMainForm form = new BaseManageForms.StandardSemiForms.StandardSemiMainForm();
            form.Show();
        }

        private void nav_StandardMix_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.StandardMixForms.StandardMixMainForm form = new BaseManageForms.StandardMixForms.StandardMixMainForm();
            form.Show();
        }

        private void nav_Role_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.AuthorityManageForms.RoleForms.RoleMainForm roleMainForm = new AuthorityManageForms.RoleForms.RoleMainForm();
            roleMainForm.Show();
        }

        private void nav_LoginUser_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.AuthorityManageForms.UserForms.LoginUserMainForm loginUserMainForm = new AuthorityManageForms.UserForms.LoginUserMainForm();
            loginUserMainForm.Show();
        }

        private void nav_SamplingPlace_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.SamplingPlaceForms.SamplingPlaceMainForm samplingPlaceMainForm = new BaseManageForms.SamplingPlaceForms.SamplingPlaceMainForm();
            samplingPlaceMainForm.Show();
        }

        private void barButtonItem_changePassWord_ItemClick(object sender, ItemClickEventArgs e)
        {
            FlyHorse.LIMS.WinApp.OtherForms.ChangePassWordForm ChangePassWordForm = new OtherForms.ChangePassWordForm();
            ChangePassWordForm.Show();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void iAbout_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (!showChildrenForm("UpdataLogForm"))
            {
                FlyHorse.LIMS.WinApp.OtherForms.UpdataLogForm form = new OtherForms.UpdataLogForm();
                form.Show();
            }

        }


        private bool showChildrenForm(string p_ChildrenFormName)
        {
            int i;
            //依次检测当前窗体的子窗体  
            for (i = 0; i < this.MdiChildren.Length; i++)
            {
                //判断当前子窗体的name属性值是否与传入的字符串值相同  
                if (this.MdiChildren[i].Name == p_ChildrenFormName)
                {
                    //此子窗体是目标子窗体，激活之  
                    this.MdiChildren[i].Activate();
                    return true;
                }
            }
            return false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            LoginUserUtil.LoginUser = null;
        }

        private void nav_MixReport_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.DataManageForms.ReportMixForms.ReportMixMainForm form = new DataManageForms.ReportMixForms.ReportMixMainForm();
            form.Show();
        }

        private void nav_SamplingPlaceMix_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.BaseManageForms.SamplingPlaceMixForms.SamplingPlaceMixMainForm form = new BaseManageForms.SamplingPlaceMixForms.SamplingPlaceMixMainForm();
            form.Show();
        }

        private void ribbonControl_Click(object sender, EventArgs e)
        {

        }

        private void nav_MonthlyReport_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FlyHorse.LIMS.WinApp.DataAnalyzeFroms.MonthlyReport.MonthReportForm form = new DataAnalyzeFroms.MonthlyReport.MonthReportForm();
            form.Show();
        }



    }
}